/*
   @Copyright:LeetCode
   @Author:   tjyemail
   @Problem:  http://leetcode.com/problems/minimum-size-subarray-sum
   @Language: C++
   @Datetime: 20-01-07 15:58
   */

class Solution {
public:
	int minSubArrayLen(int s, vector<int>& nums) {
		int len=INT_MAX;
		for(int sum=0, i=0, j=0; j<nums.size(); ++j){
			sum+=nums[j];
			for(; sum>=s; sum-=nums[i++])
				len=min(len, j-i+1);
		}
		return len==INT_MAX?0:len;
	}
};
